home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
LOGIC Apps
/
Logic-APPLE_II_APPS.iso
/
pc
/
LOGIC Apple II 5.25" Library - DOS Part 2
/
DOS037.dsk
/
ALGEBRA 1.bas
next >
Wrap
BASIC Source File
|
2012-02-16
|
8KB
|
246 lines
1 REM ***********************
2 REM ** ALGEBRA 1 **
3 REM ** BY **
4 REM ** TOM JACOBSEN **
5 REM ** GREEN APPLES **
6 REM **NORTH CENTRAL IOWA**
7 REM ***********************
20 F1 = 0:F2 = 0:F3 = 0:F4 = 0
30 MY = 2:MX = 3:B = 24:S = 100:MG = 2/3
31 S$ = "+ "
40 GOTO 5000
2000 REM INPUT TWO SETS OF COORDINATES
2010 HOME : PRINT "THIS PORTION OF THE PROGRAM GENERATES A STRAIGHT LINE EQUATION FROM TWO SETS": PRINT "OF COORDINATES SUPPLYED BY YOU."
2020 PRINT : PRINT "FIRST COORDINATES (X1,Y1)"
2030 INPUT " ENTER X1 ";X1
2035 VTAB 6: HTAB 21
2040 INPUT " ENTER Y1 ";Y1
2045 PRINT TAB( 15);"(";X1;",";Y1;")"
2046 VTAB 8
2050 PRINT "SECOND COORDINATES (X2,Y2)"
2060 INPUT " ENTER X2 ";X2
2065 VTAB 9: HTAB 21
2070 INPUT " ENTER Y2 ";Y2
2075 IF X1 = X2 AND Y1 = Y2 THEN 2046
2080 PRINT TAB( 15);"(";X2;",";Y2;")"
2085 FOR A = 1 TO 1000
2090 D = A
2095 NEXT A
2096 GOSUB 2200
2100 RETURN
2200 REM DEVELOPE EQUATION FROM COORDINATES
2210 HOME : PRINT "(";X1;",";Y1;")"; TAB( 28);"(";X2;",";Y2;")":F3 = 0:F4 = 0
2211 IF X1 < >X2 THEN 2220
2212 PRINT : PRINT "THESE COORDINATES CAN NOT BE DEFINED BY Y = M X + B. THE EQUATION FOR THIS LINE IS:"
2213 PRINT : PRINT " X = ";X1
2214 REM F3 IS INFINATE SLOPE FLAG
2215 F3 = 1
2216 GOTO 2380
2220 PRINT TAB( 15);"Y = M X + B"
2230 PRINT "M = SLOPE = (Y2-Y1) / (X2-X1)"
2235 MY = Y2 -Y1:MX = X2 -X1
2240 PRINT "M = ";MY;"/";MX
2245 F1 = 0:F2 = 0
2250 REM F1 IS CHANGE IN MY OR MX FLAG
2255 REM F2 IS WHOLE NUMBER FLAG
2260 REM FIND LOWEST COMON DENOMINATOR
2265 GOSUB 2400
2270 IF F1 = 0 THEN 2300
2275 IF F2 = 0 THEN 2290
2280 VTAB 4: HTAB 15
2285 PRINT " = ";MY/MX: GOTO 2300
2290 VTAB 4: HTAB 15
2295 PRINT " = ";MY;"/";MX
2300 PRINT "B = Y INTERCEPT"
2310 PRINT "SUBSTITUTE TO SOLVE FOR B"
2320 PRINT "B = Y - M X = Y1 - M X1"
2325 MG = MY/MX
2330 B = Y1 -MG *X1
2340 PRINT "B = ";B
2350 PRINT : PRINT "EQUATION FOR COORDINATES GIVEN"
2355 S$ = "+ ": IF B <0 THEN S$ = ""
2356 IF F2 = 0 THEN 2370
2360 PRINT : PRINT TAB( 10);"Y = ";MY/MX;" X ";S$;" ";B
2365 GOTO 2380
2370 PRINT : PRINT TAB( 10);"Y = ";MY;"/";MX;" X ";S$;" ";B
2380 PRINT : PRINT "PRESS ANY KEY TO CONTINUE"
2385 GET R$
2390 RETURN
2400 REM FIND LOWEST COMON DENOMINATOR
2401 REM NUMBER OF PRIMES ARE LIMITED TO SAVE TIME.
2402 REM THEREFORE LOWEST COMON DENOMINATOR MAY NOT ALLWAYS BE FOUND
2405 IF MX <0 AND MY <0 THEN F1 = 1
2410 IF MY/MX > = 0 THEN 2430
2420 MY = ABS(MY) *( -1):MX = ABS(MX)
2425 GOTO 2435
2430 MY = ABS(MY):MX = ABS(MX)
2435 IF MY/MX < > INT(MY/MX) THEN 2450
2440 F2 = 1:F1 = 1
2445 RETURN
2450 RESTORE
2455 DATA 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83
2456 DATA 89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167
2457 DATA 173,179,181,191,193,197,199
2460 READ A: IF A > = 199 THEN 2510
2465 IF A >MY OR A >MX THEN 2510
2470 IF MY/A < > INT(MY/A) OR MX/A < > INT(MX/A) THEN 2460
2475 MY = MY/A:MX = MX/A:F1 = 1
2480 GOTO 2465
2510 RETURN
2600 REM INPUT EQUATION
2610 F1 = 0:F2 = 0:F3 = 0:F4 = 0
2620 HOME : PRINT "THIS PORTION OF THE PROGRAM ALLOWS YOU TO ENTER THE EQUATION OF A STRAIGHT LINE"
2630 PRINT "IS THE LINE PARALEL TO THE Y AXIS?"
2640 INPUT R$
2650 IF LEFT$(R$,1) < >"Y" THEN 2700
2660 F3 = 1
2665 PRINT : PRINT "INPUT X INTERCEPT ";
2670 INPUT X1
2680 PRINT : PRINT "EQUATION X = ";X1
2685 PRINT : PRINT "PUSH ANY KEY TO CONTINUE ";
2690 GET R$
2695 RETURN
2700 PRINT : PRINT "EQUATION FORMAT IS Y = M X + B"
2710 PRINT "M = SLOPE = CHANGE IN Y / CHANGE IN X"
2720 PRINT "HOW DO YOU WANT TO ENTER M?"
2725 PRINT " 1 DECIMAL": PRINT " 2 FRACTION"
2730 INPUT F4
2735 IF F4 = 1 THEN 2750
2740 IF F4 = 2 THEN 2760
2745 HOME : GOTO 2720
2750 INPUT "ENTER M ";MY
2755 GOTO 2770
2760 INPUT "CHANGE IN Y ";MY
2765 INPUT "CHANGE IN X ";MX
2767 F1 = 0:F2 = 0: GOSUB 2400
2770 PRINT : PRINT "B = Y INTERCEPT"
2780 INPUT "ENTER B ";B
2785 S$ = "+ ": IF B <0 THEN S$ = ""
2790 PRINT : PRINT "EQUATION Y = ";
2795 IF F4 < >1 THEN 2810
2800 PRINT MY;" X ";S$;B
2805 GOTO 2850
2810 IF F2 = 1 THEN 2840
2820 PRINT MY;"/";MX;" X ";S$;B
2830 GOTO 2850
2840 PRINT MY/MX;" X ";S$;B
2850 PRINT : PRINT "PRESS ANY KEY TO CONTINUE"
2855 GET R$
2860 RETURN
2900 REM DRAW GRAPH
2910 HGR
2915 HCOLOR= 3
2920 HPLOT 150,0 TO 150,140
2925 HPLOT 80,70 TO 220,70
2930 FOR A = 0 TO 140 STEP 7
2940 HPLOT 148,A TO 152,A
2950 HPLOT 80 +A,68 TO 80 +A,72
2955 NEXT
2960 HPLOT 127,7 TO 131,7: HPLOT 129,5 TO 129,9
2965 HPLOT 133,4 TO 136,7 TO 139,4: HPLOT 136,7 TO 136,10
2970 HPLOT 232,70 TO 236,70: HPLOT 234,68 TO 234,72
2975 HPLOT 238,67 TO 244,73: HPLOT 238,73 TO 244,67
3000 REM DESIDE MAGNITUDE OF GRAPH
3010 BG = ABS(B):S = 10
3015 IF F3 = 1 THEN BG = ABS(X1)
3020 IF BG <10 THEN 3045
3030 BG = BG/10
3035 S = S *10
3040 GOTO 3020
3045 HOME : VTAB 21
3050 PRINT "EACH DIVISION = ";S/10;" UNITS."
3060 REM PRINT EQUATION AND SET UP FOR POLTTING LINE
3065 IF F3 < >1 THEN 3080
3070 PRINT "EQUATION X = ";X1
3075 GOTO 3150
3080 IF F4 < >1 THEN 3100
3085 MG = MY
3090 PRINT "EQUATION Y = ";MY;" X ";S$;B
3095 GOTO 3150
3100 IF F2 < >1 THEN 3120
3105 MG = MY/MX
3110 PRINT "EQUATION Y = ";MY/MX;" X ";S$;B
3115 GOTO 3150
3120 MG = MY/MX
3125 PRINT "EQUATION Y = ";MY;"/";MX;" X ";S$;B
3150 REM PLOT LINE
3155 IF F3 < >1 THEN 3170
3157 F5 = 0
3160 XG = X1:YG = S: GOSUB 4000
3162 XG = X1:YG = ( -1) *S: GOSUB 4000
3165 GOTO 3250
3170 F5 = 0
3175 XG = ( -1) *S
3180 YG = MG *XG +B
3185 IF YG > = ( -1) *S AND YG < = S THEN GOSUB 4000
3186 IF F5 >0 THEN 3202
3187 YG = S
3190 XG = (YG -B)/MG
3192 IF XG > = ( -1) *S AND XG < = 0 THEN GOSUB 4000
3194 IF F5 >0 THEN 3202
3196 YG = ( -1) *S
3198 XG = (YG -B)/MG
3200 IF XG > = ( -1) *S AND XG < = 0 THEN GOSUB 4000
3202 XG = S
3204 YG = MG *XG +B
3206 IF YG > = ( -1) *S AND YG < = S THEN GOSUB 4000
3208 IF F5 >1 THEN 3224
3210 YG = S
3212 XG = (YG -B)/MG
3214 IF XG > = 0 AND XG < = S THEN GOSUB 4000
3216 IF F5 >1 THEN 3224
3218 YG = ( -1) *S
3220 XG = (YG -B)/MG
3222 IF XG > = 0 AND XG < = S THEN GOSUB 4000
3224 REM PLOT LINE
3250 HPLOT X(1),Y(1) TO X(2),Y(2)
3251 IF F3 = 1 AND X1 >( -1) *S/35 AND X1 <S/35 THEN 3300
3252 IF MG < -20 AND F3 < >1 THEN 3300
3253 IF MG >20 AND F3 < >1 THEN 3300
3254 IF MG <.05 AND MG > -.05 AND B <S/50 AND B >( -1) *S/50 THEN 3300
3255 PRINT "PRESS ANY KEY TO CONTINUE ";: GET R$
3260 HOME : TEXT : RETURN
3300 REM FLASH LINE IF IT LIES ON AXIS
3310 PRINT "PRESS ANY KEY TO CONTINUE"
3320 HPLOT X(1),Y(1) TO X(2),Y(2)
3325 FOR D = 1 TO 100: NEXT
3330 HCOLOR= 3
3340 HPLOT X(1),Y(1) TO X(2),Y(2)
3345 FOR D = 1 TO 100: NEXT
3350 A = PEEK( -16384)
3360 POKE -16368,0
3370 IF A >127 THEN 3260
3380 HCOLOR= 0
3390 GOTO 3320
4000 REM CHANGE X Y COORDINATES TO HIGH RES COORDINATES
4005 X(F5 +1) = INT((XG/S *70) +.5) +150
4010 Y(F5 +1) = ( -1) * INT((YG/S *70) +.5) +70
4020 F5 = F5 +1
4030 RETURN
5000 REM MENU AND MAIN CONTROL PROGRAM
5010 HOME : VTAB 10
5015 PRINT TAB( 8);"ALGEBRA PROGRAM NUMBER 1"
5020 PRINT TAB( 14)"Y = M X + B"
5025 PRINT : PRINT " THOMAS JACOBSEN 8-26-79"
5030 FOR A = 1 TO 2000
5035 D = A
5040 NEXT A
5050 HOME : VTAB 7
5055 PRINT TAB( 18);"MENU"
5060 PRINT : PRINT TAB( 10);"1 DEMO"
5065 PRINT TAB( 10);"2 INPUT COORDINATES"
5070 PRINT TAB( 10);"3 INPUT EQUATION"
5075 PRINT TAB( 10);"4 PLOT GRAPH"
5080 PRINT TAB( 10);"5 STOP"
5085 PRINT : HTAB 12: INPUT "ENTER NUMBER ";A
5090 IF A <1 OR A >5 THEN 5050
5095 IF A < > INT(A) THEN 5050
5100 ON A GOSUB 6000,2000,2600,2900,20000
5105 GOTO 5050
6000 REM DEMO VALUES
6005 F1 = 0:F2 = 0:F3 = 0:F4 = 0
6006 S$ = "+ "
6010 MY = 2:MX = 3:B = 24:S = 100:MG = 2/3
6020 GOSUB 2900
6025 RETURN
20000 END